package com.zdgk.core.control.forward.network.listener;

import lombok.extern.slf4j.Slf4j;
import org.openmuc.j60870.Connection;
import org.openmuc.j60870.ConnectionEventListener;
import org.openmuc.j60870.ServerEventListener;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.io.IOException;

@Slf4j
@Configuration
public class IEC104ServerEventListener implements ServerEventListener {

    @Resource
    private SlaveListenerHandler slaveListenerHandler;

    @Override
    public ConnectionEventListener connectionIndication(Connection connection) {
        log.info("新的主站连接: {}",connection.getRemoteInetAddress());
        Info104.connectionList.put(connection.getRemoteInetAddress().getHostAddress(),connection);
        return slaveListenerHandler;
    }

    @Override
    public void serverStoppedListeningIndication(IOException e) {
        log.error("104TCP从站server服务器停止监听: {}" , e.getMessage());
    }

    @Override
    public void connectionAttemptFailed(IOException e) {
        log.error("连接尝试失败: {}" , e.getMessage());
    }
}
